package com.stylefeng.guns.modular.vpn_channel_action_info.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.vpn.dto.ChannelActionDTO;
import com.stylefeng.guns.modular.vpn.entity.ChannelTotalStatisticsDO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.VpnChannelActionInfo;
import com.stylefeng.guns.modular.vpn_channel_action_info.service.IVpnChannelActionInfoService;

import javax.servlet.http.HttpServletResponse;

/**
 * 渠道数据控制器
 *
 * @author fengshuonan
 * @Date 2020-06-05 22:00:09
 */
@Controller
@RequestMapping("/vpnChannelActionInfo")
public class VpnChannelActionInfoController extends BaseController {

    private String PREFIX = "/vpn_channel_action_info/vpnChannelActionInfo/";

    @Autowired
    private IVpnChannelActionInfoService vpnChannelActionInfoService;

    /**
     * 跳转到渠道数据首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "vpnChannelActionInfo.html";
    }

    /**
     * 跳转到添加渠道数据
     */
    @RequestMapping("/vpnChannelActionInfo_add")
    public String vpnChannelActionInfoAdd() {
        return PREFIX + "vpnChannelActionInfo_add.html";
    }

    /**
     * 跳转到修改渠道数据
     */
    @RequestMapping("/vpnChannelActionInfo_update/{vpnChannelActionInfoId}")
    public String vpnChannelActionInfoUpdate(@PathVariable Integer vpnChannelActionInfoId, Model model) {
        VpnChannelActionInfo vpnChannelActionInfo = vpnChannelActionInfoService.selectById(vpnChannelActionInfoId);
        model.addAttribute("item",vpnChannelActionInfo);
        LogObjectHolder.me().set(vpnChannelActionInfo);
        return PREFIX + "vpnChannelActionInfo_edit.html";
    }

    /**
     * 获取渠道数据列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(ChannelActionDTO dto) {
        return vpnChannelActionInfoService.list(dto);
    }

    /**
     * 新增渠道数据
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(VpnChannelActionInfo vpnChannelActionInfo) {
        vpnChannelActionInfoService.insert(vpnChannelActionInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除渠道数据
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer vpnChannelActionInfoId) {
        vpnChannelActionInfoService.deleteById(vpnChannelActionInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改渠道数据
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(VpnChannelActionInfo vpnChannelActionInfo) {
        vpnChannelActionInfoService.updateById(vpnChannelActionInfo);
        return SUCCESS_TIP;
    }

    /**
     * 渠道数据详情
     */
    @RequestMapping(value = "/detail/{vpnChannelActionInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("vpnChannelActionInfoId") Integer vpnChannelActionInfoId) {
        return vpnChannelActionInfoService.selectById(vpnChannelActionInfoId);
    }

    @RequestMapping("/export")
    @ResponseBody
    public void export(@RequestParam(value = "beginTime",required = false) String beginTime,
                                  @RequestParam(value = "endTime",required = false) String endTime,
                                  HttpServletResponse response){
        vpnChannelActionInfoService.export(beginTime,endTime,response);
    }

    @RequestMapping("/get/total")
    @ResponseBody
    public Object getChannelTotalInfo(@RequestParam("channelNoArr") String channelNoArr,
                                                        @RequestParam(value = "options",required = false) String options) {
        return vpnChannelActionInfoService.getChannelTotalInfo(channelNoArr,options);
    }

    /**
     * 渠道增长趋势数据
     * @param channelNoArr
     * @param options
     * @return
     */
    @RequestMapping("/get/line")
    @ResponseBody
    public Object getChannelLineInfo(@RequestParam("channelNoArr") String channelNoArr,
                                                        @RequestParam(value = "options",required = false) String options) {
        return vpnChannelActionInfoService.getChannelLine(channelNoArr,options);
    }

    /**
     * 渠道漏斗数据
     * @param channelNoArr
     * @param options
     * @return
     */
    @RequestMapping("/get/funnel")
    @ResponseBody
    public Object getChannelFunnelInfo(@RequestParam("channelNoArr") String channelNoArr,
                                     @RequestParam(value = "options",required = false) String options) {
        return vpnChannelActionInfoService.getChannelFunnel(channelNoArr,options);
    }

    /**
     * 获取渠道名称列表
     * @return
     */
    @RequestMapping("/get/names")
    @ResponseBody
    public Object getChannelNameList() {
        return vpnChannelActionInfoService.getChannelNames();
    }
}
